<?php

namespace july\julyadmin\builder\traits\actions;

use july\julyadmin\builder\Form;
/**
 * 编辑
 */

trait HasEdit
{
    public function edit()
    {
        $pk = input($this->getPk());
        if (request()->isGet()) {
            $builder      = $this->builder();
            $data         = $this->dataModel->where([$this->getPk() => $pk])->find();
            $form         = new Form($builder);
            $form->isEdit = 1;
            $form->method = 'post';
            $form->data   = $data;
            $form->pk     = $this->getPk();
            $this->buildForm($form, $form->isEdit, $data);
            $form->render();
        } else {
            return $this->save(1);
        }
    }
}
